using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class ApbatchMap : EntityTypeConfiguration<Apbatch>
    {
        public ApbatchMap()
        {
            // Primary Key
            this.HasKey(t => t.REFERENCE);

            // Properties
            this.Property(t => t.BATCH)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.ID)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.REFERENCE)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.INVNO)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.DESC)
                .HasMaxLength(40);

            this.Property(t => t.TYPE)
                .IsRequired()
                .HasMaxLength(2);

            this.Property(t => t.ENTITY)
                .IsRequired()
                .HasMaxLength(4);

            this.Property(t => t.ReceiptNo)
                .HasMaxLength(10);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            this.Property(t => t.PONo)
                .HasMaxLength(6);

            // Table & Column Mappings
            this.ToTable("Apbatch");
            this.Property(t => t.BATCH).HasColumnName("BATCH");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.REFERENCE).HasColumnName("REFERENCE");
            this.Property(t => t.INVNO).HasColumnName("INVNO");
            this.Property(t => t.DESC).HasColumnName("DESC");
            this.Property(t => t.DATE).HasColumnName("DATE");
            this.Property(t => t.BAL).HasColumnName("BAL");
            this.Property(t => t.BALDOL).HasColumnName("BALDOL");
            this.Property(t => t.BALVEND).HasColumnName("BALVEND");
            this.Property(t => t.AMT).HasColumnName("AMT");
            this.Property(t => t.AMTDOL).HasColumnName("AMTDOL");
            this.Property(t => t.AMTVEND).HasColumnName("AMTVEND");
            this.Property(t => t.DUEDATE).HasColumnName("DUEDATE");
            this.Property(t => t.TYPE).HasColumnName("TYPE");
            this.Property(t => t.DISCOUNT).HasColumnName("DISCOUNT");
            this.Property(t => t.DISCOUNTD).HasColumnName("DISCOUNTD");
            this.Property(t => t.DISCOUNTV).HasColumnName("DISCOUNTV");
            this.Property(t => t.ENTITY).HasColumnName("ENTITY");
            this.Property(t => t.CURRENCY).HasColumnName("CURRENCY");
            this.Property(t => t.PAYERTYPE).HasColumnName("PAYERTYPE");
            this.Property(t => t.CSTCTRID).HasColumnName("CSTCTRID");
            this.Property(t => t.ReceiptNo).HasColumnName("ReceiptNo");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.PONo).HasColumnName("PONo");

            // Relationships
            this.HasRequired(t => t.Batchttl)
                .WithMany(t => t.Apbatches)
                .HasForeignKey(d => d.BATCH);
            this.HasOptional(t => t.Cstctr)
                .WithMany(t => t.Apbatches)
                .HasForeignKey(d => d.CSTCTRID);
            this.HasRequired(t => t.currency1)
                .WithMany(t => t.Apbatches)
                .HasForeignKey(d => d.CURRENCY);
            this.HasRequired(t => t.Vend)
                .WithMany(t => t.Apbatches)
                .HasForeignKey(d => d.ID);

        }
    }
}
